package com.architecture.web.jsf.util;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * <p>This class has utilities methods for retrieve objects of http protocol.</p>
 * @author JR
 * @version 1.0
 * @category Http Utilities
 */
public final class HttpUtility {
	
	/**
	 * private constructor of <code>HttpUtility</code>.
	 */
	private HttpUtility() {
		super();
	}
	
	/**
	 * <p>Gets the {@linkplain ServletContext}</p>
	 * @return <code>ServletContext</code>
	 */
	public static ServletContext getApplication(){
		return (ServletContext)FacesUtility.getCurrentInstance().getExternalContext().getContext();
	}
	
	/**
	 * <p>Gets the {@linkplain HttpServletRequest}</p>
	 * @return <code>HttpServletRequest</code>
	 */
	public static HttpServletRequest getRequest() {
		return (HttpServletRequest)FacesUtility.getExternalContext().getRequest();
	}

	/**
	 * <p>Gets the {@linkplain HttpServletResponse}</p>
	 * @return <code>HttpServletResponse</code>
	 */
	public static HttpServletResponse getResponse() {
		return (HttpServletResponse)FacesUtility.getExternalContext().getResponse();
	}
	
	/**
	 * <p>Gets the {@linkplain HttpSession}</p>
	 * @param create
	 * @return <code>HttpSession</code>
	 */
	public static HttpSession getSession(final boolean create){
		return (HttpSession) FacesUtility.getExternalContext().getSession(create);
	}
	
	/**
	 * <p>Gets the {@linkplain HttpSession}</p>
	 * @param create
	 * @return <code>HttpSession</code>
	 */
	public static HttpSession getSession(){
		return (HttpSession) FacesUtility.getExternalContext().getSession(Boolean.FALSE);
	}
	
}
